package com.shenmazong.controller;

import com.github.pagehelper.PageInfo;
import com.shenmazong.pojo.TbTaskTheoryLibrary;
import com.shenmazong.service.TbTaskTheoryLibraryService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.ListParamVo;
import com.shenmazong.vo.TaskTheoryListVo;
import com.shenmazong.vo.TaskTheoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 理论作业库
 */
@RestController
@RequestMapping("/taskTheoryLibrary")
public class TaskTheoryLibraryController {
    @Autowired
    TbTaskTheoryLibraryService tbTaskTheoryLibraryService;

    /**
     * 列表
     * @param listParamVo
     * @return
     */
    @PostMapping("/findTaskTheoryLibraryList")
    public ResultResponse findTaskTheoryLibraryList(@RequestBody ListParamVo listParamVo){
        Integer current = listParamVo.getCurrent();
        Integer size = listParamVo.getSize();
        Object taskTheoryLibrary = listParamVo.getParamMap().get("taskTheoryLibrary");
        PageInfo pageInfo=tbTaskTheoryLibraryService.findTaskTheoryLibraryList(current,size,taskTheoryLibrary);
        return ResultResponse.SUCCESS(pageInfo);
    }

    /**
     * 回显
     * @param tbTaskTheoryLibrary
     * @return
     */
    @PostMapping("/echoTaskTheoryLibrary")
    public ResultResponse echoTaskTheoryLibrary(@RequestBody TbTaskTheoryLibrary tbTaskTheoryLibrary){
        return tbTaskTheoryLibraryService.echoTaskTheoryLibrary(tbTaskTheoryLibrary);
    }

    /**
     * 修改
     * @param tbTaskTheoryLibrary
     * @return
     */
    @PostMapping("/updateTaskTheoryLibrary")
    public ResultResponse updateTaskTheoryLibrary(@RequestBody TbTaskTheoryLibrary tbTaskTheoryLibrary){
        return tbTaskTheoryLibraryService.updateTaskTheoryLibrary(tbTaskTheoryLibrary);
    }

    /**
     * 删除
     * @param tbTaskTheoryLibrary
     * @return
     */
    @PostMapping("/delTaskTheoryLibrary")
    public ResultResponse delTaskTheoryLibrary(@RequestBody TbTaskTheoryLibrary tbTaskTheoryLibrary){
        return tbTaskTheoryLibraryService.delTaskTheoryLibrary(tbTaskTheoryLibrary);
    }

    /**
     * 读取Excel文件内容 返回数据集合
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public ResultResponse uploadFile(MultipartFile file) throws IOException {
        return tbTaskTheoryLibraryService.uploadFile(file);
    }


//    @PostMapping("/saveTheory")
//    public ResultResponse saveTheory(MultipartFile file,@RequestBody TaskTheoryListVo taskTheoryListVo) throws IOException {
//        ResultResponse resultResponse = tbTaskTheoryLibraryService.uploadFile(file);
//        List<TbTaskTheoryLibrary> list = (List<TbTaskTheoryLibrary>) resultResponse.getData();
//        TaskTheoryListVo taskTheoryList = new TaskTheoryListVo();
//        taskTheoryList.setLibraryList(list);
//        taskTheoryList.setSchoolId(taskTheoryListVo.getSchoolId());
//        taskTheoryList.setChapterId(taskTheoryListVo.getChapterId());
//        taskTheoryList.setCourseId(taskTheoryListVo.getCourseId());
//        return tbTaskTheoryLibraryService.onLineInputTaskTheory(taskTheoryList);
//    }

    /**
     * 上传
     * @param taskTheoryList
     * @return
     */
    @PostMapping("/onLineInputTaskTheory")
    public ResultResponse onLineInputTaskTheory(@RequestBody TaskTheoryListVo taskTheoryList){
        return tbTaskTheoryLibraryService.onLineInputTaskTheory(taskTheoryList);
    }


}
